
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package adventure_game;

import java.util.HashMap;
import java.util.Set;

/**
 * Controls the players movecount, inventory, add remove
 * @author Frank, Morten B, Ronni
 */

public class Player
{
    private HashMap<String, Item> inventory;
    private static final int MAXITEMS = 2;
    private String name;
    private int numberOfMoves;
    private Game m_game;

    public Player(String name, Game m_game)
    {
        this.name = name;
        this.m_game = m_game;
        inventory = new HashMap<String, Item>();
    }

    /**
     * Gives the name of players.
     * @return
     */
    public String getName()
    {
        return this.name;
    }

    /**
     * returns a list of items in inventory.
     * @return
     */
    public String getInventory()
    {
        String returnString = "Inventory list:";
        Set<String> keys = inventory.keySet();
        for (String item : keys)
        {
            returnString += "\n" + item;
        }
        return returnString;
    }

    /**
     * Picks up an item.
     * @param item
     */
    public void takeItem(Item item)
    {
        inventory.put(item.getName(), item);
    }

    /**
     * Makes a maximum in your inventory
     * @param item
     * @return
     */
    public boolean canCarry(Item item)
    {
        return inventory.size() < MAXITEMS;
    }

    /**
     * Drops a item from the inventory
     * @param itemName
     * @return
     */
    public Item dropItem(String itemName)
    {
        return inventory.remove(itemName);
    }

    /**
     * Adds each move to a counter.
     */
    public void addMove()
    {
        checkMoves();
        this.numberOfMoves++;
    }

/**
 * checks the number of moves currentplayer has made.
 */
    public void checkMoves()
    {
        if (this.numberOfMoves == 4)
        {
            m_game.nextPlayer();
        }
    }
}


